package test;

import static org.junit.Assert.*;

import movement.Location;

import org.junit.*;


public class testLocation {
	
	Location loc;
	
    @Before
    public void setUp() throws Exception { 
    	loc = new Location(40,50,"TestingLocation");
    }
    
    @Test
    public void testChangeLocation(){
    	Location ll = new Location(20,40,"TEE");
    	Location l1 = new Location(10,30,"TE");
    	assertEquals(l1.getX(),10);
    	assertEquals(l1.getY(),30);
    	assertEquals(l1.getName(),"TE");
    	
    	l1.changeLocation(ll, 10);
    	
    	//used after advanceTime, to compute the new location
    	assertEquals(l1.getX(),18);
    	assertEquals(l1.getY(),38);
    	assertEquals(l1.getName(),"heading for TEE");
    }
    
    @Test
    public void testCompareTo(){
    	Location l1 = new Location(30,30,"L1");	
    	Location l2 = new Location(30,60,"L2");
    	Location l3 = new Location(30,90,"L3");
    	assertEquals(0,l1.compareTo(l3, l2));
    	assertEquals(-1,l2.compareTo(l1, l3));
    	assertEquals(1,l1.compareTo(l2, l3));
    }
    
    @Test
    public void testComputeDistance1(){
    	Location l1 = new Location(30,30,"L1");	
    	Location l2 = new Location(30,60,"L2");
    	Double result = l1.distance(l2);
    	assertEquals(30 , result, 1);
    }
    
    @Test
    public void testComputeDistance2(){
    	Location l1 = new Location(30,30,"L1");	
    	Double result = l1.distance(30,103);
    	assertEquals(73 , result, 1);
    }
    
    @Test
    public void testCreateGettersAndSetters() {
    	assertEquals(loc.getName(),"TestingLocation");
    	assertEquals(loc.getX(), 40);
    	assertEquals(loc.getY(), 50);
    	loc.setName("SecondName");
    	assertEquals(loc.getName(),"SecondName");
    }
    
    @Test
    public void testCreateLocationString(){
    	Location l1 = new Location("(10","30)","TE");
    	assertEquals(l1.getX(),10);
    	assertEquals(l1.getY(),30);
    	assertEquals(l1.getName(),"TE");
    }
    
    @SuppressWarnings("unused")
	@Test (expected=IllegalArgumentException.class)
    public void testCreateLocationStringIllegal(){
    	Location l1 = new Location("(1d0","30d)","TE");    	
    }
    
    @Test
    public void testEquals(){
    	Location l1 = new Location(30,30,"L1");	
    	Location l2 = new Location(30,60,"L2");
    	Location l3 = new Location(30,60,"L3");
    	assertTrue(l2.equals(l3));
    	assertFalse(l1.equals(l2));
    	assertFalse(l1.equals(l3));
    }
}
